//
//  HUserInfo.m
//  HTanzhi
//
//  Created by 陈贵 on 15/11/10.
//  Copyright © 2015年 hzj. All rights reserved.
//

#import "HUserInfo.h"

@interface HUserInfo ()
//头像
@property (strong, nonatomic)  UIButton *iconB;

//介绍文本
@property (nonatomic ,strong)  UILabel *introL;

//注册按钮
@property (nonatomic ,strong) UIButton *registerB;

//登陆按钮
@property (nonatomic ,strong) UIButton *enterB;

//红色分割线
@property (nonatomic ,strong) UIView *lineV;

//底部灰色部分
@property (nonatomic ,strong) UIView *bottomV;
@end

@implementation HUserInfo

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
//    NSLog(@"%f",self.view.frame.size.height);
    
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
        NSLog(@"%f",self.view.frame.size.height);

}

///设置UI
- (void) setUI{
    
    _iconB = [self addBthWithImage:@"iconNotLogin" andTitle:nil andAction:nil];
    //------
    _introL = [[UILabel alloc]init];
    _introL.text = @"hahaha";
    [self.view addSubview:_introL];
    //------
    _registerB = [self addBthWithImage:nil andTitle:@"注册" andAction:@selector(cilckTheRegisterB)];
    //------
    _enterB = [self addBthWithImage:nil andTitle:@"登陆" andAction:@selector(cilckTheEnterB)];
    //-----
    _lineV = [[UIView alloc]init];
    _lineV.backgroundColor = [UIColor redColor];
    [self.view addSubview:_lineV];
    //----
    _bottomV = [[UIView alloc]init];
    _bottomV.backgroundColor = [UIColor grayColor];
    [self.view addSubview:_bottomV];
}

- (CGFloat)heightWithIsEnter:(BOOL)isEnter{
    
    CGFloat w = [UIScreen mainScreen].bounds.size.width;
    CGFloat h = [UIScreen mainScreen].bounds.size.height;
    
    if (isEnter) {
        self.distanceLeft = w * 0.5;
        
    }else{
        self.distanceLeft = 180;
    }
    self.enterB.hidden = isEnter;
    self.registerB.hidden = isEnter;
    self.lineV.hidden = isEnter;
    
    //两按钮的高度
    CGFloat Bh = 40;
    self.iconB.bounds = CGRectMake( 0, 0, 80, 80);
    self.iconB.center = CGPointMake( self.distanceLeft, h  * 0.1);
    //------
    [self.introL sizeToFit];
    self.introL.center = CGPointMake(self.iconB.center.x, CGRectGetMaxY(self.iconB.frame) + self.introL.frame.size.height * 0.5 + 10);
    //------
    self.registerB.frame = CGRectMake(0, CGRectGetMaxY(self.introL.frame), w * 0.5, Bh);
    //------
    self.enterB.frame = CGRectMake(w * 0.5, CGRectGetMaxY(self.introL.frame), w * 0.5, Bh);
    //-----
    self.lineV.bounds = CGRectMake(0, 0, 1, Bh * 0.6);
    self.lineV.center = CGPointMake( w * 0.5, self.registerB.frame.origin.y + Bh * 0.5);
    //-----
    self.bottomV.frame = CGRectMake(0, CGRectGetMaxY(self.registerB.frame), w, 20);
    
    
    NSLog(@"%lf",CGRectGetMaxY(self.bottomV.frame));
    return CGRectGetMaxY(self.bottomV.frame);
    
}


///生成按钮
- (UIButton *) addBthWithImage:(NSString *)iconName andTitle:(NSString *)title andAction:(SEL)action{
    
    UIButton *bth = [UIButton buttonWithType:UIButtonTypeCustom];
    [bth setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    if (iconName) {
        UIImage *imageB = [UIImage imageNamed:iconName];
        if (!imageB) {
            NSLog(@"请确认图片名");
        }
        [bth setImage:imageB forState:UIControlStateNormal];
    }
    if (action) {
        [bth addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    }
    [bth setTitle:title forState:UIControlStateNormal];
    [self.view addSubview:bth];
    return bth;
}
- (void) cilckTheRegisterB {
    _distanceLeft = [UIScreen mainScreen].bounds.size.width * 0.5;
    NSLog(@"%f",self.distanceLeft);
    NSLog(@"11111");
    
}
- (void) cilckTheEnterB {
    _distanceLeft = 50;
    [self.view layoutIfNeeded];
    
    UIViewController *v = [[UIViewController alloc]init];
    v.view.frame = [UIScreen mainScreen].bounds;
    v.view.backgroundColor = [UIColor whiteColor];
    
    [self.navigationController pushViewController:v animated:YES];
    
}
- (void)dealloc{
    NSLog(@"2");
}
#pragma 懒加载
- (UIButton *)iconB
{
    if (!_iconB) {
        _iconB = [self addBthWithImage:@"iconNotLogin" andTitle:nil andAction:nil];
    }
    return _iconB;
}
- (UILabel *)introL
{
    if (!_introL) {
        _introL = [[UILabel alloc]init];
        _introL.text = @"hahaha";
        [self.view addSubview:_introL];
    }
    return _introL;
}
- (UIButton *)registerB
{
    if (_registerB) {
        _registerB = [self addBthWithImage:nil andTitle:@"注册" andAction:@selector(cilckTheRegisterB)];
    }
    return _registerB;
}
- (UIButton *)enterB
{
    if (_enterB) {
        _enterB = [self addBthWithImage:nil andTitle:@"登陆" andAction:@selector(cilckTheEnterB)];
    }
    return _enterB;
}
- (UIView *)lineV
{
    if (_lineV) {
        _lineV = [[UIView alloc]init];
        _lineV.backgroundColor = [UIColor redColor];
        [self.view addSubview:_lineV];
    }
    return _lineV;
}
- (UIView *)bottomV
{
    if (_bottomV) {
        _bottomV = [[UIView alloc]init];
        _bottomV.backgroundColor = [UIColor grayColor];
        [self.view addSubview:_bottomV];
    }
    return _bottomV;
}

@end




